class random_access_t{
public:
  random_access_t(const char * filename, off_t rows, off_t cols);
  ~random_access_t();
  inline float extract_val(off_t row, off_t col);
  void extract_vec(off_t row, unsigned int len, float *  vec);
  static void marshall(ostream & os, float * vec, int len);
private:
  FILE * pFile;
  off_t floatlen;
  //ifstream ifs;
  off_t rows,cols;
};

inline float random_access_t::extract_val(off_t row,off_t col){
  off_t pos = floatlen*(row*cols+col);
  int rc = fseeko(pFile,pos,SEEK_SET);
  off_t tell = ftello(pFile);
  if(tell!=pos){
    cerr<<"Tell does not match seek in extract_val!\n";
    cerr<<"Tell is "<<tell<<endl;
    cerr<<"Error code is "<<rc<<endl;
    exit(1);
  }
  char buffer2[floatlen];
  fread(buffer2,floatlen,1,pFile);
  float * newval2 = reinterpret_cast< float *>(buffer2);
  return *newval2;
}
